package com.iyjhsoc.game.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.iyjhsoc.game.dao.*;
import com.iyjhsoc.game.domain.VO.CompetitionVO;
import com.iyjhsoc.game.domain.dto.PlayerDTO;
import com.iyjhsoc.game.domain.entity.*;
import com.iyjhsoc.game.domain.response.Response;
import com.iyjhsoc.game.exception.BusinessException;
import com.iyjhsoc.game.service.UtilService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UtilServiceImpl implements UtilService {
    @Autowired
    CompetitionSmallGameDAO competitionSmallGameDAO;
    @Autowired
    TeamDAO teamDAO;
    @Autowired
    CompetitionSmallTeamLoLInfoDAO competitionSmallTeamLoLInfoDAO;
    @Autowired
    CompetitionDAO competitionDAO;
    @Autowired
    PlayerDAO playerDAO;
    @Autowired
    PlayerGameTeamDAO playerGameTeamDAO;
    @Autowired
    SmallGamePlayerLolInfoDAO smallGamePlayerLolInfoDAO;
    @Autowired
    GameRoleDAO gameRoleDAO;
    @Autowired
    GameChooseRolesDAO gameChooseRolesDAO;
    @Autowired
    CompetitionSmallTeamInfoDAO competitionSmallTeamInfoDAO;
    @Override
    public Response getCompetitionData(String data, String competitionId) {
        JSONObject blblData = JSON.parseObject(data);
        JSONObject team_left = (JSONObject) blblData.get("team_left");
        JSONObject team_right = (JSONObject) blblData.get("team_right");
        CompetitionSmallGameDO competitionSmallGameDO = competitionSmallGameDAO.selectById(competitionId);
        TeamDO team_name_left = teamDAO.getTeamByName((String) team_left.get("team_name"), "2");
        TeamDO team_name_right = teamDAO.getTeamByName(team_right.getString("team_name"),"2");
        CompetitionDO competitionDO = competitionDAO.selectById(competitionSmallGameDO.getCompetitionId());
        if(competitionDO.getTeamOneId().equals(team_name_right.getId())){
            if(!competitionDO.getTeamTowId().equals(team_name_left.getId())){
                throw new BusinessException("比赛信息错误队伍对不上");
            }
        } else if(competitionDO.getTeamTowId().equals(team_name_right.getId())){
            if(!competitionDO.getTeamOneId().equals(team_name_left.getId())){
                throw new BusinessException("比赛信息错误队伍对不上");
            }
        }
        CompetitionSmallTeamLoLInfoDO leftSmallTeamInfo = getSmallTeamInfo(team_left);
        List<PlayerDTO> playerLeft = getPlayerInfo(team_left);
        List<PlayerDTO> playerRight = getPlayerInfo(team_right);
        for(PlayerDTO playerDTO: playerLeft){
            Boolean aBoolean = addPlayInfo(playerDTO, team_name_left.getId(), Integer.valueOf(competitionId));
        }
        for(PlayerDTO playerDTO: playerRight){
            addPlayInfo(playerDTO,team_name_right.getId(),Integer.valueOf(competitionId));
        }
        leftSmallTeamInfo.setTeamId(team_name_left.getId());
        leftSmallTeamInfo.setSmallGameId(Long.valueOf(competitionId));
        CompetitionSmallTeamLoLInfoDO rightSmallTeamInfo = getSmallTeamInfo(team_right);
        rightSmallTeamInfo.setTeamId(team_name_right.getId());
        rightSmallTeamInfo.setSmallGameId(Long.valueOf(competitionId));
        CompetitionSmallTeamLoLInfoDO competitionSmallTeamLoLInfoDO = competitionSmallTeamLoLInfoDAO.selectByGameIdAndTeamId(rightSmallTeamInfo.getSmallGameId(), rightSmallTeamInfo.getTeamId());
        int right = 0;
        if(competitionSmallTeamLoLInfoDO == null) {
            right = competitionSmallTeamLoLInfoDAO.insert(rightSmallTeamInfo);
        } else {
            rightSmallTeamInfo.setId(competitionSmallTeamLoLInfoDO.getId());
            right = competitionSmallTeamLoLInfoDAO.updateById(rightSmallTeamInfo);
        }
        CompetitionSmallTeamLoLInfoDO leftTeamInfo = competitionSmallTeamLoLInfoDAO.
                selectByGameIdAndTeamId(leftSmallTeamInfo.getSmallGameId(), leftSmallTeamInfo.getTeamId());
        int left = 0;
        if(leftTeamInfo == null) {
            left = competitionSmallTeamLoLInfoDAO.insert(leftSmallTeamInfo);
        } else {
            leftSmallTeamInfo.setId(leftTeamInfo.getId());
            left = competitionSmallTeamLoLInfoDAO.updateById(leftSmallTeamInfo);
        }
        if(right == 1 && left == 1){
            return Response.SUCCESS("新增成功");
        } else {
            throw new BusinessException("新增失败");
        }
    }

    @Override
    public Response getKpLCompetition(String data, String matchId) {
        JSONObject val = JSONObject.parseObject(data);
        JSONArray results = val.getJSONArray("results");
        for(Object competition: results){
            JSONObject competitionVal = (JSONObject) competition;
            CompetitionDO competitionDO = fillCompetitionKPL(competitionVal);
            competitionDO.setMatchId(Long.valueOf(matchId));
            String match_id = competitionVal.getString("match_id");
            competitionDO.setOutNet(match_id);
            competitionDO.setGameId(1);
            QueryWrapper<CompetitionDO> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("game_id","1");
            queryWrapper.eq("match_id",matchId);
            queryWrapper.eq("competition_date",competitionDO.getCompetitionDate());
            CompetitionDO competitionDO1 = competitionDAO.selectOne(queryWrapper);
            if(competitionDO1 == null){
                competitionDAO.insert(competitionDO);
            } else {
                competitionDO.setId(competitionDO1.getId());
                competitionDAO.updateById(competitionDO);
            }
        }

        return Response.SUCCESS("成功增加"+results.size()+"条数据");
    }

    @Override
    public Response<List<CompetitionSmallGameDO>> getBattleId(String data,CompetitionDO competitionDO) {
        JSONObject val = JSONObject.parseObject(data);
        JSONArray results = val.getJSONArray("results");
        List<CompetitionSmallGameDO> list = new ArrayList<>();
        for(Object result:results){
            CompetitionSmallGameDO competitionSmallGameDO = new CompetitionSmallGameDO();
            JSONObject smallGame = (JSONObject) result;
            Integer win_camp = smallGame.getInteger("win_camp");
            Integer game_duration = smallGame.getInteger("game_duration");
            Integer battle_seq = smallGame.getInteger("battle_seq");
            String battle_id = smallGame.getString("battle_id");
            game_duration/=1000;
            if(win_camp == 1){
                competitionSmallGameDO.setVictoryTeamId(competitionDO.getTeamOneId());
            } else if(win_camp == 2){
                competitionSmallGameDO.setVictoryTeamId(competitionDO.getTeamTowId());
            }
            competitionDO.setGameId(competitionDO.getGameId());
            competitionSmallGameDO.setMatchTime(game_duration.toString());
            competitionSmallGameDO.setGameNumber(battle_seq);
            competitionSmallGameDO.setBattleId(battle_id);
            competitionSmallGameDO.setCompetitionId(competitionDO.getId());
            QueryWrapper<CompetitionSmallGameDO> queryWrapper =new QueryWrapper<>();
            queryWrapper.eq("competition_id",competitionDO.getId());
            queryWrapper.eq("game_number",battle_seq);
            CompetitionSmallGameDO competitionSmallGameDO1 = competitionSmallGameDAO.selectOne(queryWrapper);
            if(competitionSmallGameDO1 != null){
                competitionSmallGameDO.setId(competitionSmallGameDO1.getId());
                competitionSmallGameDAO.updateById(competitionSmallGameDO);
            } else {
                int insert = competitionSmallGameDAO.insert(competitionSmallGameDO);
            }
            list.add(competitionSmallGameDO);
        }
        return Response.SUCCESS(list);
    }

    @Override
    public Response insertKplSmallGame(String data, CompetitionSmallGameDO competitionSmallGameDO) {
        JSONObject val = JSONObject.parseObject(data);
        JSONObject smallData = val.getJSONObject("data");
        Integer win_camp = smallData.getInteger("win_camp");
        JSONObject camp1 = smallData.getJSONObject("camp1");
        JSONObject camp2 = smallData.getJSONObject("camp2");
        TeamDO team1 = teamDAO.getTeamByName(camp1.getString("team_name"), "1");
        TeamDO team2 = teamDAO.getTeamByName(camp2.getString("team_name"), "1");
        if(win_camp == 1){
            competitionSmallGameDO.setVictoryTeamId(team1.getId());
        } else if(win_camp == 2){
            competitionSmallGameDO.setVictoryTeamId(team1.getId());
        }
        JSONArray battle_player_list = smallData.getJSONArray("battle_player_list");
        for(Object battle_player_o:battle_player_list){
            JSONObject battle_player =  (JSONObject) battle_player_o;
            PlayerDO playerDO = fillPlayerKpl(battle_player);
            String position_desc = battle_player.getString("position_desc");
            PlayerGameTeamDO playerGameTeamDO = fillPlayerGameKpl(battle_player, playerDO,competitionSmallGameDO.getId().toString());
            fillGameChooseRolesKpl(battle_player,playerGameTeamDO,competitionSmallGameDO.getId().toString(),position_desc);
        }
        fillSmallTeamInfo(camp1,competitionSmallGameDO.getId().toString(),team1.getId().toString());
        fillSmallTeamInfo(camp2,competitionSmallGameDO.getId().toString(),team1.getId().toString());
        Boolean is_win1 = camp1.getBoolean("is_win");
        Boolean is_win2 = camp2.getBoolean("is_win");
        if(is_win1){
            competitionSmallGameDO.setVictoryTeamId(team1.getId());
            competitionSmallGameDO.setFailTeamId(team2.getId());
        }
        if(is_win2){
            competitionSmallGameDO.setVictoryTeamId(team2.getId());
            competitionSmallGameDO.setFailTeamId(team1.getId());
        }
        Integer killNum1 = camp1.getInteger("kill_num");
        Integer killNum2 = camp2.getInteger("kill_num");
        competitionSmallGameDO.setTotalKill(killNum1+killNum2);

        competitionSmallGameDAO.updateById(competitionSmallGameDO);

        return Response.SUCCESS("成功");
    }

    @Override
    public Response getLPLMatchInfo(String matchId, String data) {
        JSONObject val = JSONObject.parseObject(data);
        JSONArray msg = val.getJSONArray("msg");
        for(Object competition:msg){
            JSONObject com = (JSONObject) competition;
            CompetitionDO competitionDO = new CompetitionDO();
            competitionDO.setGameId(2);
            Date matchDate = com.getDate("MatchDate");
            competitionDO.setCompetitionDate(matchDate);
            String outNet = com.getString("bMatchId");
            competitionDO.setOutNet(outNet);
            String bMatchName = com.getString("bMatchName").replaceAll("G1","").replaceAll("G2","")
                    .replaceAll("G4","").replaceAll("G5","").replaceAll("G6","")
                    .replaceAll("G7","");
            String[] team = bMatchName.split("vs");
            TeamDO teamByNameA = teamDAO.getTeamByName(team[0].trim(), "2");
            TeamDO teamByNameB = teamDAO.getTeamByName(team[1].trim(), "2");
            competitionDO.setTeamOneName(teamByNameA.getName());
            competitionDO.setTeamOneId(teamByNameA.getId());
            competitionDO.setTeamTowId(teamByNameB.getId());
            competitionDO.setTeamTowName(teamByNameB.getName());
            String MatchWin = com.getString("MatchWin");
            if("1".equals(MatchWin)){
                competitionDO.setVictoryTeamId(teamByNameA.getId());
            }
            if("2".equals(MatchWin)){
                competitionDO.setVictoryTeamId(teamByNameB.getId());
            }
            Integer bo = com.getInteger("GameMode");
            Integer scoreA = com.getInteger("ScoreA");
            Integer scoreB = com.getInteger("ScoreB");
            competitionDO.setBo(bo);
            competitionDO.setGameNum(scoreA+scoreB);
            competitionDO.setMatchId(Long.valueOf(matchId));
            String gameTypeName = com.getString("GameTypeName");
            competitionDO.setCompetitionGroup(gameTypeName);
            QueryWrapper<CompetitionDO> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("game_id","2");
            queryWrapper.eq("match_id",matchId);
            queryWrapper.eq("competition_date",competitionDO.getCompetitionDate());
            CompetitionDO competitionDO1 = competitionDAO.selectOne(queryWrapper);
            if(competitionDO1 != null){
                competitionDO.setId(competitionDO1.getId());
                competitionDAO.updateById(competitionDO);
            } else {
                competitionDAO.insert(competitionDO);
            }
        }
        return null;
    }


    public CompetitionDO fillCompetitionKPL(JSONObject data){
        CompetitionDO competitionDO = new CompetitionDO();
        Integer bo = data.getInteger("bo");
        JSONObject camp1 = data.getJSONObject("camp1");
        JSONObject camp2 = data.getJSONObject("camp2");
        Date time = data.getDate("start_time");
        competitionDO.setCompetitionDate(time);
        competitionDO.setBo(bo);
        TeamDO team1 = teamDAO.getTeamByName(camp1.getString("team_name"), String.valueOf(1));
        TeamDO team2 = teamDAO.getTeamByName(camp2.getString("team_name"),String.valueOf(1));
        JSONArray gameNum = data.getJSONArray("match_battle_video_list");
        Integer win_camp = data.getInteger("win_camp");
        if(win_camp == 1){
            competitionDO.setVictoryTeamId(team1.getId());
        } else if(win_camp  == 2) {
            competitionDO.setVictoryTeamId(team2.getId());
        }
        String matchId = data.getString("matchId");
        competitionDO.setTeamOneName(team1.getName());
        competitionDO.setTeamOneId(team1.getId());
        competitionDO.setTeamTowId(team2.getId());
        competitionDO.setTeamTowName(team2.getName());
        competitionDO.setCompetitionGroup("常规赛");
        competitionDO.setGameNum(gameNum.size());
        competitionDO.setOutNet(matchId);
        return competitionDO;
    }

    public CompetitionSmallTeamLoLInfoDO getSmallTeamInfo(JSONObject teamData){
        CompetitionSmallTeamLoLInfoDO competitionSmallTeamLoLInfoDO = new CompetitionSmallTeamLoLInfoDO();
        JSONArray ext2 =  teamData.getJSONArray("ext2");
        for(Object resources:ext2){
            JSONObject val = (JSONObject) resources;
            String name = val.getString("name");
            if("小龙数".equals(name)){
                competitionSmallTeamLoLInfoDO.setXiaoLong(getNum(val));
            } else if("大龙数".equals(name)){
                competitionSmallTeamLoLInfoDO.setDaLong(getNum(val));
            } else if("防御塔".equals(name)){
                competitionSmallTeamLoLInfoDO.setTower(getNum(val));
            }
        }
        competitionSmallTeamLoLInfoDO.setKills(teamData.getInteger("kills"));
        competitionSmallTeamLoLInfoDO.setAssists(teamData.getInteger("assists"));
        competitionSmallTeamLoLInfoDO.setDeath(teamData.getInteger("deaths"));

        return competitionSmallTeamLoLInfoDO;
    }

    public List<PlayerDTO> getPlayerInfo(JSONObject teamData){
        JSONArray player_list =teamData.getJSONArray("player_list");
        List<PlayerDTO> list = new ArrayList<>();
        for(Object player: player_list){
            PlayerDTO playerDO = new PlayerDTO();
            JSONObject p = (JSONObject)player;
            String nickname = p.getString("nickname");
            String position = p.getString("position_id");
            playerDO.setName(nickname);
            playerDO.setGameId(2);
            if("3".equals(position)) {
                playerDO.setPosition(1);
            } else if("4".equals(position)){
                playerDO.setPosition(2);
            } else if("2".equals(position)){
                playerDO.setPosition(3);
            } else if("1".equals(position)){
                playerDO.setPosition(4);
            } else if("5".equals(position)){
                playerDO.setPosition(5);
            }
            list.add(playerDO);
        }
        return list;
    }


    public Boolean addPlayInfo(PlayerDTO playerDTO,Long teamId,Integer smallGameId){
        PlayerDO playerDO = playerDAO.selectByGameIdAndName(playerDTO.getName(), String.valueOf(playerDTO.getGameId()));
        if(playerDO  != null){
            PlayerGameTeamDO playerGameTeamDO = playerGameTeamDAO.selectByPlayerAndTeamIdAndGameId(playerDO.getId(), teamId,1L);
            if(playerGameTeamDO == null){
                QueryWrapper<PlayerGameTeamDO> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("player_id",playerDO.getId());
                queryWrapper.eq("small_game_id",smallGameId);
                PlayerGameTeamDO playerGameTeamDO1 = playerGameTeamDAO.selectOne(queryWrapper);
                if(playerGameTeamDO1 != null){
                    return true;
                }
                playerGameTeamDO = new PlayerGameTeamDO();
                playerGameTeamDO.setTeamId(teamId);
                playerGameTeamDO.setPlayerId(playerDO.getId());
                playerGameTeamDO.setPosition(playerDTO.getPosition());
                playerGameTeamDO.setSmallGameId(smallGameId);
                playerGameTeamDAO.insert(playerGameTeamDO);
            }
            return true;
        }
        playerDO = new PlayerDO();
        playerDO.setName(playerDTO.getName());
        playerDO.setGameId(playerDTO.getGameId());
        int insert = playerDAO.insert(playerDO);
        playerDTO.setId(playerDO.getId());
        QueryWrapper<PlayerGameTeamDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("player_id",playerDO.getId());
        queryWrapper.eq("small_game_id",smallGameId);
        PlayerGameTeamDO playerGameTeamDO1 = playerGameTeamDAO.selectOne(queryWrapper);
        if(playerGameTeamDO1 != null){
            return true;
        }
        // 新增选手信息
        PlayerGameTeamDO playerGameTeamDO = new PlayerGameTeamDO();
        playerGameTeamDO.setTeamId(teamId);
        playerGameTeamDO.setPlayerId(playerDO.getId());
        playerGameTeamDO.setPosition(playerDTO.getPosition());
        playerGameTeamDAO.insert(playerGameTeamDO);
        SmallGamePlayerLolInfoDO smallGamePlayerLolInfoDO = new SmallGamePlayerLolInfoDO();
        smallGamePlayerLolInfoDO.setPlayerId(playerDO.getId());
        smallGamePlayerLolInfoDO.setAssists(playerDTO.getAssists());
        smallGamePlayerLolInfoDO.setKills(playerDTO.getKills());
        smallGamePlayerLolInfoDO.setDeaths(playerDTO.getDeaths());
        smallGamePlayerLolInfoDO.setExt(playerDTO.getExt());
        return true;
    }

    public Integer getNum(JSONObject val){
        JSONArray value = val.getJSONArray("value");
        JSONObject object = value.getJSONObject(0);
        String num = object.getString("num");
        return Integer.valueOf(num);
    }


    public PlayerDO fillPlayerKpl(JSONObject battle_player){
        String player_name = battle_player.getString("player_name");
        PlayerDO playerDO = playerDAO.selectByGameIdAndName(player_name, "1");
        if(playerDO == null){
            playerDO = new PlayerDO();
        } else {
            return playerDO;
        }
        playerDO.setGameId(1);
        playerDO.setName(player_name);
        playerDAO.insert(playerDO);
        return playerDO;
    }


    public PlayerGameTeamDO fillPlayerGameKpl(JSONObject battle_player,PlayerDO playerDO,String smallGame){
        PlayerGameTeamDO playerGameTeamDO  = new PlayerGameTeamDO();
        String team_name = battle_player.getString("team_name");
        TeamDO teamByName = teamDAO.getTeamByName(team_name, "1");
        playerGameTeamDO.setPlayerId(playerDO.getId());
        playerGameTeamDO.setTeamId(teamByName.getId());
        String position_desc = battle_player.getString("position_desc");
        if("游走".equals(position_desc)){
            playerGameTeamDO.setPosition(5);
        } else if("打野".equals(position_desc)) {
            playerGameTeamDO.setPosition(2);
        } else if("对抗路".equals(position_desc)){
            playerGameTeamDO.setPosition(1);
        } else if("中路".equals(position_desc)){
            playerGameTeamDO.setPosition(3);
        } else if("发育路".equals(position_desc)){
            playerGameTeamDO.setPosition(4);
        }
        playerGameTeamDO.setSmallGameId(Integer.valueOf(smallGame));
        PlayerGameTeamDO playerGameTeamDO1 = playerGameTeamDAO.selectByPlayerAndTeamIdAndGameId(playerDO.getId(), teamByName.getId(), Long.valueOf(smallGame));
        if(playerGameTeamDO1 == null){
            playerGameTeamDAO.insert(playerGameTeamDO);
        } else {
            playerGameTeamDO.setId(playerGameTeamDO1.getId());
            playerGameTeamDAO.updateById(playerGameTeamDO);
        }
        return playerGameTeamDO;
    }

    public GameChooseRolesDO fillGameChooseRolesKpl(JSONObject battle_player,PlayerGameTeamDO playerDO,String smallGameId,String positionDesc){
        GameChooseRolesDO fillGame = new GameChooseRolesDO();
        fillGame.setCompetitionSmallGameId(Long.valueOf(smallGameId));
        fillGame.setPositionDesc(positionDesc);
        fillGame.setPosition(playerDO.getPosition());
        String hero_name = battle_player.getString("hero_name");
        Integer gold = battle_player.getInteger("gold");
        GameRoleDO gameRoleDO = gameRoleDAO.selectByGameRoleName(hero_name, "1");
        fillGame.setGameRoleId(gameRoleDO.getId());
        fillGame.setPlayerId(playerDO.getPlayerId());
        fillGame.setTeamId(playerDO.getTeamId());
        fillGame.setGold(gold);
        Integer kill_num = battle_player.getInteger("kill_num");
        Integer death_num = battle_player.getInteger("death_num");
        Integer assist_num = battle_player.getInteger("assist_num");
        String participation_rate = battle_player.getString("participation_rate");
        Integer is_mvp = battle_player.getInteger("is_mvp");
        fillGame.setKillNum(kill_num);
        fillGame.setDeathNum(death_num);
        fillGame.setAssistsNum(assist_num);
        fillGame.setParticipateRate(new BigDecimal(participation_rate));
        fillGame.setIsMvp(is_mvp);
        QueryWrapper<GameChooseRolesDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("competition_small_game_id",smallGameId);
        queryWrapper.eq("player_id",playerDO.getPlayerId());
        GameChooseRolesDO gameChooseRolesDO = gameChooseRolesDAO.selectOne(queryWrapper);
        if(gameChooseRolesDO == null){
            gameChooseRolesDAO.insert(fillGame);
        } else {
            fillGame.setId(gameChooseRolesDO.getId());
            gameChooseRolesDAO.updateById(fillGame);
        }
        return fillGame;
    }

    public CompetitionSmallTeamInfoDO fillSmallTeamInfo(JSONObject team,String smallGameId,String teamId){
        CompetitionSmallTeamInfoDO smallTeamInfoDO = new CompetitionSmallTeamInfoDO();
        smallTeamInfoDO.setTeamId(Long.valueOf(teamId));
        smallTeamInfoDO.setCompetitionSmallGameId(Long.valueOf(smallGameId));
        Boolean is_win = team.getBoolean("is_win");
        if(is_win) {
            smallTeamInfoDO.setIsVictory(1);
        }
        Integer kill_num = team.getInteger("kill_num");
        Integer assist_num = team.getInteger("assist_num");
        Integer death_num = team.getInteger("death_num");
        Integer gold = team.getInteger("gold");
        // 大龙
        Integer kill_big_dragon_num = team.getInteger("kill_big_dragon_num");
        // 黑暗暴君
        Integer kill_dark_tyrant_num = team.getInteger("kill_dark_tyrant_num");
        // 推塔数
        Integer push_tower_num = team.getInteger("push_tower_num");
        // 暴君数
        Integer kill_tyrant_num = team.getInteger("kill_tyrant_num");
        // 风暴龙王
        Integer kill_storm_dragon_king_num = team.getInteger("kill_storm_dragon_king_num");
        // 先知主宰
        Integer kill_prophet_dragon_num = team.getInteger("kill_prophet_dragon_num");
        smallTeamInfoDO.setKillNum(kill_num);
        smallTeamInfoDO.setAssistsNum(assist_num);
        smallTeamInfoDO.setDeathNum(death_num);
        smallTeamInfoDO.setGold(gold);
        smallTeamInfoDO.setDefenseTower(push_tower_num);
        smallTeamInfoDO.setTyrant(kill_tyrant_num);
        smallTeamInfoDO.setDarkTyrant(kill_dark_tyrant_num);
        smallTeamInfoDO.setDominate(kill_prophet_dragon_num);
        smallTeamInfoDO.setDarkDominate(kill_big_dragon_num);
        smallTeamInfoDO.setStorm(kill_storm_dragon_king_num);
        QueryWrapper<CompetitionSmallTeamInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("competition_small_game_id",smallGameId);
        queryWrapper.eq("team_id",teamId);
        CompetitionSmallTeamInfoDO smallTeamInfoDO1 = competitionSmallTeamInfoDAO.selectOne(queryWrapper);
        if(smallTeamInfoDO1 == null){
            competitionSmallTeamInfoDAO.insert(smallTeamInfoDO);
        } else {
            smallTeamInfoDO.setId(smallTeamInfoDO1.getId());
            competitionSmallTeamInfoDAO.updateById(smallTeamInfoDO);
        }
        return smallTeamInfoDO;
    }


}
